<?php

/**
 * Created by lihong.
 * Date: 2017/5/18
 * Time: 11:13
 */

/**
 * Class MyTool 常用工具类
 */
class MyTool
{
    /**
     * @param string $sMsg
     * @param string $sUrl
     */
    public static function alertGo($sMsg, $sUrl){
        if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
            $temp['msg'] = $sMsg;
            $temp['url'] = $sUrl;
            echo json_encode($temp);
            exit;
        }else{
            echo '<script>alert("'.$sMsg.'");window.location.href = "' . $sUrl . '";</script>';
            exit;
        }
    }

    /**
     * @param string $sMsg
     * @param string $sUrl
     */
    public static function alertBack($sMsg,$sUrl = ''){
        if('' == $sUrl){
            echo '<script>alert("'.$sMsg.'");history,back();</script>';
            exit;
        }else{
            echo '<script>alert("'.$sMsg.'");window.location.href = "' . $sUrl . '";</script>';
            exit;
        }

    }
}